<?php
include_once "lib/config.php";
require_once("includes/pagetop.php");
			
$helpCatinfo=$pdodbobj->fetch_array($pdodbobj->query("select * from help_categories order by help_cat_id"));

if(isset($_REQUEST["c"]) && $_REQUEST["c"]!="")
{
	$helpCatID=toInternalId(trim($_REQUEST["c"]));
}
else
{
	$helpCatID=$helpCatinfo[0]["help_cat_id"];
}

$query="select * from helps ";
$where=" where status=1 ";
$name = '';
$conditionarr=array();
$catcondition=" ";

if(strlen(trim($_REQUEST['search_help_text'])) > 0) 
{
	$disAllowChars = array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '\'');
	$refinedString = str_replace($disAllowChars, ' ',$_REQUEST['search_help_text']);
	$srcName = explode(' ', $refinedString);
	if(is_array($srcName) && count($srcName) > 0) 
	{
		for($i=0; $i < COUNT($srcName); $i++) 
		{
			if($name == '') 
			{
				if($where == '') 
				{
					$name = " WHERE (help_question LIKE '%".$srcName[$i]."%'";
				} 
				else 
				{
					$name = " and (help_question LIKE '%".$srcName[$i]."%'";
				}
			} 
			else 
			{
				$name .= " OR help_question LIKE '%".$srcName[$i]."%'";
		 
			}
		}
		$name .= ')';
	}
	$norecordMsg="There is no help related to your search.";
}
else
{
	$conditionarr=array(":help_cat_id"=>$helpCatID);
	$catcondition=" and help_cat_id=:help_cat_id ";
	$norecordMsg="There is no help in this category.";
}

$helpinfo=$pdodbobj->fetch_array($pdodbobj->query($query.$where.$name.$catcondition." order by help_question",$conditionarr));

//if(!is_array($helpinfo) || count($helpinfo)<1)
//{
//	redirect("help.php");
//}

//for($i=0; $i<count($helpCatinfo); $i++)
//{
//	$conditionarr=array(":help_cat_id"=>$helpCatinfo[$i]["help_cat_id"]);
//	$helpinfo[$i]=$pdodbobj->fetch_array($pdodbobj->query("select * from helps where status=1 and help_cat_id=:help_cat_id order by help_question",$conditionarr));
//
//}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>AllyFolio | Help Center </title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />
<script src="js/jquery1.10.2.min.js"></script>
</head>

<body>
<style>
	.help-question
	{
		text-decoration: none;
		color: #0B1419;
	}
	.error-msg-span
	{
		color: #FF0000;
	}
</style>
	<div id="main_wrapper">
	    <?php
	    $pageheading="Help Center";
	    require_once("includes/header.php");
	    ?>
	    <!--=================Body Contain Start=======================-->
	    <div class="wrapper">
	    	<div class="header">
	        	<div class="contain-wrap">
	        	
	            	<div class="help-title">Help Center</div>
	                
	                <div class="search_bar">
	                	<form method="post" name="search_help_form" onsubmit="return checkSearchString();">
	                		<span class="carve_left"></span>
		                    <span class="search_area"><input type="text" placeholder="How Can I Help You?" name="search_help_text" id="search_help_text" value="<?php if(strlen(trim($_REQUEST['search_help_text'])) > 0){echo trim($_REQUEST['search_help_text']);} ?>" /></span>
		                    <a href="javascript:void(0);" onclick="return checkSearchString();" class="search_btn"></a>
						</form>
	                </div>
	                <div class="clearfix"></div>
	          
	            
					<div class="help_btn" style="width:auto;padding-right:15px;">
						<ul>
						<?php
							foreach($helpCatinfo as $catinfo)
							{
						?>
							<li><a href="help.php?c=<?php echo toPublicId($catinfo["help_cat_id"]); ?>" ><?php echo $catinfo["help_cat_name"]; ?></a></li>
						<?php
							}
						?>
						</ul>
					</div>
					<div >
					<?php
						if(is_array($helpinfo) && count($helpinfo)>0)
						{
							$questionCounter=0;
							foreach($helpinfo as $helpquestion)
							{
								$questionCounter++;
						?>
						<div style="padding-bottom:10px;">
							<div>
								<a class="help-question" href="javascript:void(0);" onclick="return displayAnswer('<?php echo $helpquestion["help_id"]; ?>');"><?php echo $questionCounter.". ".$helpquestion["help_question"]; ?></a>
							</div>
							<div id="help_answer_<?php echo $helpquestion["help_id"]; ?>" style="display:none;padding-top:8px;"><?php echo $helpquestion["help_answer"]; ?></div>
						</div>
						<?php		
							}
						}
						else
						{
					?>
					
						<span class="error-msg-span"><?php echo $norecordMsg; ?></span>
					<?php		
						}	
					?>
					</div>			
					
	            </div>
	            <div class="clearfix"></div>
			</div>
	    </div>
    	<div class="clearfix"></div>
    <!--=================Body Contain end=======================-->
    </div>
<?php
    require_once("includes/footer.php");
?>
<script>
var currentOpen=0;
function checkSearchString()
{
	if((document.getElementById("search_help_text").value.trim())=="")
	{
		document.getElementById("search_help_text").focus();
		return false;
	}
	else
	{
		document.search_help_form.submit();
	}
}
function displayAnswer(questionid)
{
	if(currentOpen>0)
	{
		document.getElementById("help_answer_"+currentOpen).style.display="none";
	}
	document.getElementById("help_answer_"+questionid).style.display="";
	currentOpen=questionid;
	return false;
}
</script>